package Collection;

import domain.Student;

import java.util.Collection;
import java.util.ArrayList;


public class CollectionTest1 {
    public static void main(String[] args) {
//        method();
        Collection<Student> c1=new ArrayList<>();
        c1.add(new Student("张三",23));
        c1.add(new Student("李四",26));
        c1.add(new Student("王五",26));
        System.out.println("c1集合的长度是:"+c1.size());
        System.out.println(c1.contains("王五"));
        c1.remove(new Student("李四",26));
        System.out.println(c1);
        System.out.println(c1.size());
        boolean b = c1.contains(new Student("李四", 26));
        System.out.println(b);

    }

    private static void method() {
        Collection<String> c=new ArrayList<>();
        c.add("zhangsan");
        c.add("lisi");
        c.add("wangwu");
        c.remove("lisi");
//        c.clear()是清除c集合里所有的元素
//        c.clear();
        final var lisi = c.contains("lisi");
        System.out.println(lisi);

        System.out.println(c);
//        a1代表是否添加成功，添加成功就是true,否则就是false
        final var a1 = isA1(c);
        System.out.println(a1);
        boolean a2=c.add("a1");
        System.out.println(c);
        boolean b1=c.isEmpty();
        System.out.println("c集合是否有元素:"+b1);
        c.clear();
        boolean b2=c.isEmpty();
        System.out.println("c集合是否有元素:"+b2);
//        c=null;
        System.out.println(c.size());
        System.out.println(c);
        boolean b4=c.contains("zhaosi");
        System.out.println("c集合里是否有zhaosi元素"+b4);
        try {
            boolean b3=c.isEmpty();
            System.out.println("c集合是否有元素:"+b3);
        }catch (NullPointerException e){
            System.out.println(e.getMessage());
        }
    }

    private static boolean isA1(Collection<String> c) {
        boolean a1= c.add("a1");
        return a1;
    }
}
